Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed assignment to catch block parameter #15384

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

dk2k
Copy link
Contributor

@dk2k dk2k commented Aug 23, 2024

Fixed assignment to catch block parameter

Signed-off-by: Dmitry Kryukov <dk2k@ya.ru>
Copy link
Contributor

✅ Gradle check result for d140044: SUCCESS

Copy link

codecov bot commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 71.99%. Comparing base (abb1041) to head (d140044).
Report is 306 commits behind head on main.

Files with missing lines Patch % Lines
...main/java/org/opensearch/search/SearchService.java 50.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #15384      +/-   ##
============================================
+ Coverage     71.93%   71.99%   +0.06%     
- Complexity    63223    63285      +62     
============================================
  Files          5214     5214              
  Lines        295938   295939       +1     
  Branches      42754    42754              
============================================
+ Hits         212876   213074     +198     
+ Misses        65601    65376     -225     
- Partials      17461    17489      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dblock
Copy link
Member

dblock commented Aug 23, 2024

Could really use a test on this path.

@dblock dblock added backport 2.x Backport to 2.x branch skip-changelog labels Aug 23, 2024
@opensearch-trigger-bot
Copy link
Contributor

This PR is stalled because it has been open for 30 days with no activity.

@opensearch-trigger-bot opensearch-trigger-bot bot added the stalled Issues that have stalled label Sep 23, 2024
@opensearch-trigger-bot opensearch-trigger-bot bot removed the stalled Issues that have stalled label Sep 24, 2024
@dbwiddis dbwiddis merged commit ebcf5e3 into opensearch-project:main Oct 17, 2024
63 of 65 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 17, 2024
Signed-off-by: Dmitry Kryukov <dk2k@ya.ru>
(cherry picked from commit ebcf5e3)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
dbwiddis pushed a commit that referenced this pull request Oct 17, 2024
(cherry picked from commit ebcf5e3)

Signed-off-by: Dmitry Kryukov <dk2k@ya.ru>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
dk2k added a commit to dk2k/OpenSearch that referenced this pull request Oct 17, 2024
: new OpenSearchException(e.getCause());
Exception exception = e;
if (exception instanceof ExecutionException) {
exception = (exception.getCause() == null || exception.getCause() instanceof Exception)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbwiddis Does this logic make sense? If exception.getCause() is null, then we assign null to exception, which is going to NPE when we do throw exception; three lines later. Am I reading this right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrross I didn't fully study the logic, as it already existed.

The only change here was really making a copy of the e argument passed to the catch block and renaming all the other e to exception. It actually would have made a smaller diff had it been catch (Exception ex) followed by Exception e = ex and then no other changes.

That said, I see the former logic does include casting null as an Exception and then rethrowing it later. But all that said, will the cause of an ExecutionException ever be null in this situation? I don't think so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree this change is good by itself.

The existing logic seems to be quite wonky, but I think you're right that the contract of ExecutionException is that the cause will never be null.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the contract of ExecutionException is that the cause will never be null.

I think you can explicitly create one with the no-param constructor. But I can't find any instances of that in the OpenSearch codebase, and most other handling of this instanceof don't even bother to check for null. So we could probably remove the null check. It's an NPE in either case, just a different spot in the code.

dk2k added a commit to dk2k/OpenSearch that referenced this pull request Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants